//
//  OrderHistoryViewController.m
//  OrderAssistant
//
//  Created by chendong on 2020/8/26.
//  Copyright © 2020 chendong. All rights reserved.
//

#import "OrderHistoryViewController.h"
#import "OrderHistoryTableViewCell.h"
#import "OrderHistoryInfoViewController.h"
#import "TDL_SelectDateView.h"
#import "NetTools.h"
#import <SVProgressHUD.h>
#import "CellModelFrame.h"
#import "CargoBoxViewController.h"
#import "FCUUID.h"
#import <AFNetworking.h>
#import "THDatePickerView.h"
#import "AppDelegate.h"
@interface OrderHistoryViewController ()<UITableViewDelegate,UITableViewDataSource,THDatePickerViewDelegate,TDL_SelectDateViewDelegate>{
//    TDL_SelectDateView *_dataView;
}
@property(nonatomic,strong) UITableView *myTableView;
@property(nonatomic,strong) NSMutableArray *myTableViewArr;
@property(nonatomic,strong) NSMutableArray *dataDDIC;
@property(nonatomic,strong) NSDictionary *dataDic;
@property(nonatomic,strong) OrderHistoryTableViewCell *dataDicCell;
@property(nonatomic,strong) NSIndexPath *dataDicCellIndexPath;
@property(nonatomic,strong) NSIndexPath *lastcellPath;
@property(nonatomic,strong) UIView *noView;
@property(nonatomic,strong) UIView *dateBgV;
@property(nonatomic,strong) UIButton *startBtn;
@property(nonatomic,strong) UIButton *endBtn;
@property(nonatomic,strong) UIButton *nowbtn;
@property(nonatomic,strong) THDatePickerView *dateView;
@property(nonatomic,strong) UIView *mbV;
@property(nonatomic,strong) AppDelegate *appmbV;
@end

@implementation OrderHistoryViewController
- (UIView *)mbV{
    if (!_mbV) {
        UIApplication *a = [UIApplication sharedApplication];
        _mbV = [[UIView alloc]initWithFrame:self.view.bounds];
        _mbV.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
        _mbV.hidden = YES;
        [a.keyWindow addSubview:_mbV];
    }
    return _mbV;
}
#pragma mark - THDatePickerViewDelegate
/**
 保存按钮代理方法

 @param timer 选择的数据
 */
- (void)datePickerViewSaveBtnClickDelegate:(NSString *)timer {
    self.mbV.hidden = YES;
    [self.nowbtn setTitle:timer forState:UIControlStateNormal];
    [UIView animateWithDuration:0.3 animations:^{
        self.dateView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 300);
    }];

}
/**
 取消按钮代理方法
 */
- (void)datePickerViewCancelBtnClickDelegate {
    self.mbV.hidden = YES;
    [UIView animateWithDuration:0.3 animations:^{
        self.dateView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 300);
    }];
}
-(void)endAction:(UIButton *)btn{
    self.mbV.hidden = NO;
    self.nowbtn = btn;
    self.dateView.date = btn.titleLabel.text;
    self.dateView.title = @"结束时间";
    [UIView animateWithDuration:0.3 animations:^{
        self.dateView.frame = CGRectMake(0, self.view.frame.size.height - 300, self.view.frame.size.width, 300);
        [self.dateView show];
    }];
}
-(void)startAction:(UIButton *)btn{
    self.mbV.hidden = NO;
    self.nowbtn = btn;
    self.dateView.date = btn.titleLabel.text;
    self.dateView.title = @"开始时间";
    [UIView animateWithDuration:0.3 animations:^{
        self.dateView.frame = CGRectMake(0, self.view.frame.size.height - 300, self.view.frame.size.width, 300);
        [self.dateView show];
    }];
}
-(THDatePickerView *)dateView{
    if (!_dateView) {
        UIApplication *a = [UIApplication sharedApplication];
        _dateView = [[THDatePickerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 300)];
        _dateView.delegate = self;
        _dateView.title = @"请选择时间";
        _dateView.isSlide = NO;
        _dateView.minuteInterval = 1;
        [a.keyWindow addSubview:_dateView];
    }
    return _dateView;
}
-(UIView *)dateBgV{
    if (!_dateBgV){
        _dateBgV = [[UIView alloc]initWithFrame:CGRectMake(0, kNavBarAndStatusBarHeight, SCREENWIDTH, 50)];
        _dateBgV.backgroundColor = RGBCOLOR(238,238,238);
        UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        btn1.frame = CGRectMake(10, 7, [UIScreen mainScreen].bounds.size.width / 2 - 50, _dateBgV.frame.size.height-14);
        [btn1 setBackgroundColor:[UIColor whiteColor]];
        btn1.layer.borderWidth = 1;
        btn1.layer.borderColor = RGBCOLOR(200, 200, 200).CGColor;
        btn1.layer.cornerRadius = 5;
        btn1.clipsToBounds = YES;
        NSDate * date = [NSDate date];
        NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
        //一周的秒数
        NSTimeInterval time = 7 * 24 * 60 * 60;
        //一分钟的秒数
        NSTimeInterval time2 = 60;
        //下周就把"-"去掉
        NSDate *lastWeek = [date dateByAddingTimeInterval:-time];
        NSString *startDate =  [dateFormatter stringFromDate:lastWeek];
        [btn1 setTitle:[NSString stringWithFormat:@"%@ 00:00",[[startDate componentsSeparatedByString:@" "] firstObject]] forState:UIControlStateNormal];
        [btn1 setTitleColor:RGBCOLOR(180, 180, 180) forState:UIControlStateNormal];
        btn1.titleLabel.font = [UIFont systemFontOfSize:15];
        [_dateBgV addSubview:btn1];
        self.startBtn = btn1;
        [btn1 addTarget:self action:@selector(startAction:) forControlEvents:UIControlEventTouchUpInside];
        UILabel *l = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(btn1.frame), btn1.frame.origin.y, 25, btn1.frame.size.height)];
        l.text = @"--";
        l.textAlignment = NSTextAlignmentCenter;
        [_dateBgV addSubview:l];
        UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
        btn2.backgroundColor = [UIColor whiteColor];
        btn2.frame = CGRectMake(CGRectGetMaxX(l.frame), btn1.frame.origin.y, btn1.frame.size.width, btn1.frame.size.height);
        btn2.layer.borderWidth = 1;
        btn2.layer.borderColor = RGBCOLOR(200, 200, 200).CGColor;
        btn2.layer.cornerRadius = 5;
        btn2.clipsToBounds = YES;
        NSDate *lastWeek1 = [date dateByAddingTimeInterval:time2];
        NSString *startDate1 =  [dateFormatter stringFromDate:lastWeek1];
        [btn2 setTitle:[NSString stringWithFormat:@"%@",startDate1] forState:UIControlStateNormal];
//        NSDate *date1 = [NSDate date];
//        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//        [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
//        NSString *str = [formatter stringFromDate:startDate1];
//        [btn2 setTitle:str forState:UIControlStateNormal];
        [btn2 setTitleColor:RGBCOLOR(180, 180, 180) forState:UIControlStateNormal];
        btn2.titleLabel.font = [UIFont systemFontOfSize:15];
        [btn2 addTarget:self action:@selector(endAction:) forControlEvents:UIControlEventTouchUpInside];
        [_dateBgV addSubview:btn2];
        self.endBtn = btn2;
        UIButton *quedingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        quedingBtn.backgroundColor = RGBCOLOR(111, 186, 249);
        quedingBtn.layer.cornerRadius = 3;
        quedingBtn.clipsToBounds = YES;
        [quedingBtn setTitle:@"查询" forState:UIControlStateNormal];
        quedingBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [quedingBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        quedingBtn.frame = CGRectMake(CGRectGetMaxX(btn2.frame)+5, btn1.frame.origin.y+1, _dateBgV.frame.size.width-CGRectGetMaxX(btn2.frame)-10, btn1.frame.size.height-2);
        [_dateBgV addSubview:quedingBtn];
        [self.view addSubview:_dateBgV];
        [quedingBtn addTarget:self action:@selector(quedingBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _dateBgV;
}
-(void)quedingBtnAction:(UIButton *)btn{
    self.mbV.hidden = YES;
    [self requestRankingWithStartDate:self.startBtn.titleLabel.text endDate:self.endBtn.titleLabel.text];
}
-(UIView *)noView{
    if (!_noView) {
        _noView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.dateBgV.frame), SCREENWIDTH, SCREENHEIGHT-CGRectGetMaxY(self.dateBgV.frame))];
        _noView.backgroundColor = RGBCOLOR(230, 230, 230);
        [self.view addSubview:_noView];
        UIImageView *noIMGv = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 115, 115)];
        noIMGv.center = CGPointMake(_noView.frame.size.width/2, _noView.frame.size.height/2);
        noIMGv.image = [UIImage imageNamed:@"icon_empty.png"];
        [_noView addSubview:noIMGv];
        UILabel *lllll = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(noIMGv.frame), SCREENWIDTH, 50)];
        lllll.text = @"空空如也";
        lllll.textAlignment = NSTextAlignmentCenter;
        lllll.textColor = RGBCOLOR(181, 181, 181);
        [_noView addSubview:lllll];
    }
    return _noView;
}
-(NSMutableArray *)dataDDIC{
    if (!_dataDDIC) {
        _dataDDIC = [[NSMutableArray alloc]init];
    }
    return _dataDDIC;
}
-(NSMutableArray *)myTableViewArr{
    if (!_myTableViewArr) {
        _myTableViewArr = [[NSMutableArray alloc]init];
    }
    return _myTableViewArr;
}
-(UITableView *)myTableView{
    if (!_myTableView) {
        _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.dateBgV.frame), SCREENWIDTH, SCREENHEIGHT-kTabBarHeight-CGRectGetMaxY(self.dateBgV.frame)-20) style:UITableViewStylePlain];
        _myTableView.dataSource = self;
        _myTableView.delegate = self;
        _myTableView.separatorStyle = UITableViewCellSelectionStyleNone;
//        _myTableView.backgroundColor = [UIColor blueColor];
        [self.view addSubview:_myTableView];
    }
    return _myTableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"历史订单";
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIView *leftV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    leftV.userInteractionEnabled = YES;
    UIButton *gwcBtnl = [UIButton buttonWithType:UIButtonTypeCustom];
    gwcBtnl.userInteractionEnabled = NO;
    gwcBtnl.frame = CGRectMake(0, 5, 30, 30);
    [gwcBtnl setImage:[UIImage imageNamed:@"货框_03.png"] forState:UIControlStateNormal];
    gwcBtnl.imageView.contentMode = UIViewContentModeScaleAspectFit;
    UITapGestureRecognizer *t = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(leftAction:)];
    [leftV addGestureRecognizer:t];
//    [gwcBtnl addTarget:self action:@selector(leftAction:) forControlEvents:UIControlEventTouchUpInside];
    [leftV addSubview:gwcBtnl];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftV];
    
//    _dataView = [[TDL_SelectDateView alloc] init];
//    _dataView.frame = CGRectMake(0, kNavBarAndStatusBarHeight, SCREENWIDTH, 50);
//   [_dataView show];
//   _dataView.delegate = self;
//   [self.view addSubview:_dataView];
    
    
    [self mbV];
    
    [self dateBgV];
    
    UIView *bottomBGV = [[UIView alloc]initWithFrame:CGRectMake(0, SCREENHEIGHT-kTabBarHeight-20, SCREENWIDTH, kTabBarHeight+20)];
    bottomBGV.backgroundColor = RGBCOLOR(235, 235, 235);
    [self.view addSubview:bottomBGV];
    UIButton *lsddBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    lsddBtn.frame = CGRectMake(10, 15, bottomBGV.frame.size.width-20, 40);
    lsddBtn.backgroundColor = RGBCOLOR(108, 185, 252);
    lsddBtn.layer.cornerRadius = 5;
    [lsddBtn setTitle:@"订单详情" forState:UIControlStateNormal];
    [lsddBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [bottomBGV addSubview:lsddBtn];
    [lsddBtn addTarget:self action:@selector(lsddxqBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self myTableView];
    
    
//    NSMutableArray *dateArr =  [_dataView gainStartDateAndEndDate];
//    [self requestRankingWithStartDate:[dateArr firstObject] endDate:[dateArr lastObject]];
    [self requestRankingWithStartDate:self.startBtn.titleLabel.text endDate:self.endBtn.titleLabel.text];
    
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(xiadanleAction:) name:@"xiadanle" object:nil];
}
//-(void)xiadanleAction:(NSNotificationCenter *)not{
//    NSMutableArray *dateArr =  [_dataView gainStartDateAndEndDate];
//    [self requestRankingWithStartDate:[dateArr firstObject] endDate:[dateArr lastObject]];
//}
-(void)leftAction:(UITapGestureRecognizer *)item{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark -- 搜索按钮事件
- (void)doTheRefreshWithStart:(NSString *)start end:(NSString *)end{
    if (![start isEqualToString:@""] && ![end isEqualToString:@""]) {
        // 请求
        [self requestRankingWithStartDate:start endDate:end];
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请选择时间" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}
-(void)requestRankingWithStartDate:(NSString *)startDate endDate:(NSString *)endDate{
    [SVProgressHUD showWithStatus:@"加载中" maskType:SVProgressHUDMaskTypeClear];
    NSDictionary *dic = @{
        @"strDateS":startDate,
        @"strDateE":endDate,
        @"strReview":@"1"
    };

    NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"ipaddress"];
    if (str.length == 0) {
        // 请求头
//        NSString *accessPath = @"http://192.168.0.19:80/Api/OrderGoods/GetOrderInf";
        NSString *accessPath = @"http://crm.zhenyea.com/Api/OrderGoods/GetOrderInf";
        // 请求参数字典
        NSDictionary *params = @{
            @"strOrganizationNo":[NSString stringWithFormat:@"%@",self.userData[@"OrganizationNo"]],
//            @"strOrderID":[NSString stringWithFormat:@"%@",self.editDicccc[@"OrderID"]],
            @"strUserId":[NSString stringWithFormat:@"%@",self.userData[@"UserID"]],
            @"strPassword":[NSString stringWithFormat:@"%@",self.userData[@"UserPass"]],
            @"strIMEI":[FCUUID uuidForVendor],
            @"strDateS":startDate,
            @"strDateE":endDate
        };

        //创建配置信息
        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
        //设置请求超时时间：5秒
        configuration.timeoutIntervalForRequest = 5;
        //创建会话
        NSURLSession *session = [NSURLSession sessionWithConfiguration: configuration delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
        NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",accessPath]]];
        //设置请求方式：POST
        [request setHTTPMethod:@"POST"];
        [request setValue:@"application/json" forHTTPHeaderField:@"content-Type"];
        [request setValue:@"application/json;charset=gb2312" forHTTPHeaderField:@"Accept"];
        
        //data的字典形式转化为data
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:nil];
        //设置请求体
        [request setHTTPBody:jsonData];
        
        NSURLSessionDataTask * dataTask =[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
            [SVProgressHUD dismiss];
            if (error == nil) {
                NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
                NSString *receiveStr = [[NSString alloc]initWithData:data encoding:encoding];
                NSData * aData = [receiveStr dataUsingEncoding:NSUTF8StringEncoding];
                NSError *errorr = nil;
                id response = [NSJSONSerialization JSONObjectWithData:aData options:NSJSONReadingMutableContainers error:&errorr];
                if ([response isKindOfClass:[NSDictionary class]]) {
                    // 请求成功数据处理
                    NSString *IsResult = [NSString stringWithFormat:@"%@",[response objectForKey:@"IsResult"]];
                    if ([IsResult isEqualToString:@"1"]) {
                        NSArray *a = response[@"Data"];
                        [self.myTableViewArr removeAllObjects];
                        [self.dataDDIC removeAllObjects];
                        for (int i=0; i<a.count; i++) {
                            CellModelFrame *f = [[CellModelFrame alloc]init];
                            f.dic = a[i];
                            [self.myTableViewArr addObject:f];
                            [self.dataDDIC addObject:a[i]];
                        }
                        [self.myTableView reloadData];
                        if (self.myTableViewArr.count == 0) {
                            self.noView.hidden = NO;
                        }else{
                            self.noView.hidden = YES;
                        }
                    }else{
                        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                        [SVProgressHUD setMinimumDismissTimeInterval:0.2f];
                        [SVProgressHUD showImage:[UIImage imageNamed:@""] status:[NSString stringWithFormat:@"%@",response[@"Message"]]];
                    }
                } else {
                    [SVProgressHUD showWithStatus:[NSString stringWithFormat:@"%@",response[@"Message"]] maskType:SVProgressHUDMaskTypeClear];
                }
            }else{
                NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
                NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                NSLog(@"服务器的错误原因:%@",str);
                [SVProgressHUD dismiss];
            }
        }];
        [dataTask resume];
        
        
//        AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
//
//        NSMutableURLRequest *request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:accessPath parameters:params error:nil];
//        request.timeoutInterval = 10.f;
//        [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
//        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
//
//        NSURLSessionDataTask *task = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
//            if (!error) {
//                if ([responseObject isKindOfClass:[NSDictionary class]]) {
//                    // 请求成功数据处理
//                    NSString *IsResult = [NSString stringWithFormat:@"%@",[responseObject objectForKey:@"IsResult"]];
//                    if ([IsResult isEqualToString:@"1"]) {
//                        NSArray *a = responseObject[@"Data"];
//                        [self.myTableViewArr removeAllObjects];
//                        [self.dataDDIC removeAllObjects];
//                        for (int i=0; i<a.count; i++) {
//                            CellModelFrame *f = [[CellModelFrame alloc]init];
//                            f.dic = a[i];
//                            [self.myTableViewArr addObject:f];
//                            [self.dataDDIC addObject:a[i]];
//                        }
//                        [self.myTableView reloadData];
//                        if (self.myTableViewArr.count == 0) {
//                            self.noView.hidden = NO;
//                        }else{
//                            self.noView.hidden = YES;
//                        }
//                    }else{
//                        [SVProgressHUD showWithStatus:[NSString stringWithFormat:@"%@",responseObject[@"Message"]] maskType:SVProgressHUDMaskTypeClear];
//                    }
//                } else {
//                    
//                }
//                [SVProgressHUD dismiss];
//            } else {
//                NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
//                NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
//                NSLog(@"服务器的错误原因:%@",str);
//                [SVProgressHUD dismiss];
//            }
//        }];
//
//        [task resume];
    }else{
        [NetTools postWithUrl:[NSString stringWithFormat:@"http://%@/ldcy/OrderGoods/OrderGoods.asmx/GetOrderInf",str] pararms:dic
         success:^(id  _Nonnull json) {
    //        [SVProgressHUD dismiss];
            if ([[NSString stringWithFormat:@"%@",json[@"IsResult"]] isEqualToString:@"1"]) {
                NSArray *a = json[@"Data"];
                [self.myTableViewArr removeAllObjects];
                [self.dataDDIC removeAllObjects];
                for (int i=0; i<a.count; i++) {
                    CellModelFrame *f = [[CellModelFrame alloc]init];
                    f.dic = a[i];
                    [self.myTableViewArr addObject:f];
                    [self.dataDDIC addObject:a[i]];
                }
                [self.myTableView reloadData];
                if (self.myTableViewArr.count == 0) {
                    self.noView.hidden = NO;
                }else{
                    self.noView.hidden = YES;
                }
            }else{
                [SVProgressHUD showWithStatus:[NSString stringWithFormat:@"%@",json[@"Message"]] maskType:SVProgressHUDMaskTypeClear];
            }
            [SVProgressHUD dismiss];
        } fail:^(NSError * _Nonnull error) {
            NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
            NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSLog(@"服务器的错误原因:%@",str);
            [SVProgressHUD dismiss];
        }];
    }
}
-(void)lsddxqBtnAction:(UIButton *)btn{
    if (self.dataDic) {
        //历史订单详情
        OrderHistoryInfoViewController *ohifVC = [[OrderHistoryInfoViewController alloc]init];
        ohifVC.dic = self.dataDic;
        ohifVC.userData = self.userData;
        [self.navigationController pushViewController:ohifVC animated:YES];
    }else{
        UIAlertView *a = [[UIAlertView alloc]initWithTitle:@"亲，请先选择订单哦！" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [a show];
    }
}
#pragma mark <UITableViewDelegate,UITableViewDataSource>
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.myTableViewArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *idf = @"OrderHistoryTableViewCell";
    OrderHistoryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:idf];
    if (!cell) {
        cell = [[OrderHistoryTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idf];
    }
    cell.dic = self.myTableViewArr[indexPath.row];
    __weak typeof(self) weakSelf = self;
    cell.editBlock = ^(CellModelFrame * _Nonnull cmf) {
        CargoBoxViewController *cbVC = [[CargoBoxViewController alloc]init];
        cbVC.houseDic = weakSelf.ckHouse;
        cbVC.userDic = weakSelf.userData;
        CellModelFrame *cccc = weakSelf.myTableViewArr[indexPath.row];
        cbVC.editDicccc = cccc.dic;
        cbVC.oid = [NSString stringWithFormat:@"%@",cccc.dic[@"OrderID"]];
        [weakSelf.navigationController pushViewController:cbVC animated:YES];
    };
    if (indexPath.row == self.dataDicCellIndexPath.row && self.dataDicCell) {
        cell.bgV.backgroundColor = RGBACOLOR(108, 185, 252, 0.3);
    }else{
        cell.bgV.backgroundColor = [UIColor whiteColor];
    }
    return cell;
}
//-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    return 135;
//}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    self.dataDicCell.bgV.backgroundColor = [UIColor whiteColor];
    OrderHistoryTableViewCell *lastcell = [tableView cellForRowAtIndexPath:self.lastcellPath];
    lastcell.bgV.backgroundColor = [UIColor whiteColor];
    self.lastcellPath = indexPath;
    OrderHistoryTableViewCell *c = [tableView cellForRowAtIndexPath:indexPath];
    c.bgV.backgroundColor = RGBACOLOR(108, 185, 252, 0.3);
    self.dataDicCell = c;
    CellModelFrame *cccc = self.myTableViewArr[indexPath.row];
    self.dataDic = cccc.dic;
    self.dataDicCellIndexPath = indexPath;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CellModelFrame *f = self.myTableViewArr[indexPath.row];
    return f.cellH;
    
}
@end
